<?php
/* 
 * Copyright (c) 2018-2021   All rights reserved.
 * 
 * 创建时间：2021-05-07 12:16
 *
 * 项目：upload  -  $  - install.php
 *
 * 作者：liwei 
 */

//安装或更新完成自动删除此文件和data目录

namespace modules\levpays\modules\alipay\migrations;

!defined('INLEV') && exit('Access Denied LEV');


use Lev;
use lev\base\Adminv;
use lev\base\Migrationv;
use lev\helpers\cacheFileHelpers;
use lev\helpers\dbHelper;
use lev\helpers\ModulesHelper;
use lev\helpers\SettingsHelper;
use lev\widgets\inputs\inputsWidget;

Adminv::checkAccess();

class _update extends _migrationHelper
{

    public static function actionUpdate() {
        static::updateTableSchema();

        static::updateModuleInfo();
        static::updateSettings();

        static::insertNewData();

        inputsWidget::setCaches();
        ModulesHelper::setCaches();

        static::createFile();

        static::deleteInstallFile();
    }

    public static function updateTableSchema() {
        //_install::createTables();

        //$sql = "ALTER TABLE `pre_levsd_guess_log` ADD `award` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '奖金额度' AFTER `guess`; ";
        //dbHelper::existsField('pre_levsd_guess_log', 'award') || dbHelper::executeSql($sql);

    }

    public static function createFile() {

        if (empty(Lev::$app['isDiscuz'])) {
            if (is_file($__file = __DIR__ . '/data/alipayNotifyGate.php')) {
                @file_put_contents(Lev::$aliases['@webroot'] . '/levpays_alipay_notify.php', str_ireplace('!defined(', '//!defined(', @file_get_contents($__file)));
            }

            if (is_file($__file = __DIR__ . '/data/alipayReturnGate.php')) {
                @file_put_contents(Lev::$aliases['@webroot'] . '/levpays_alipay_return.php', str_ireplace('!defined(', '//!defined(', @file_get_contents($__file)));
            }
        }else {

            if (is_file($__file = __DIR__ . '/data/alipayNotifyGate_discuz.php')) {
                @file_put_contents(Lev::$aliases['@webroot'] . '/levpays_alipay_notify.php', str_ireplace('!defined(', '//!defined(', @file_get_contents($__file)));
            }

            if (is_file($__file = __DIR__ . '/data/alipayReturnGate_discuz.php')) {
                @file_put_contents(Lev::$aliases['@webroot'] . '/levpays_alipay_return.php', str_ireplace('!defined(', '//!defined(', @file_get_contents($__file)));
            }

        }

    }

}